import {
    getDictList, getActiveTypeDict,
    getActivateUserList, getVerificationUserList,
    getShopListDict
} from "@/api/common/index";
export default {
    data() {
        return {
            deptAreaList: []
        }
    },
    methods: {
        // 初始化页面所需字典
        async initGetDicts() {
            let _self = this
            let arr = _self.selectProp ? _self.selectProp['selectList'].filter(item => item.deptType && item.deptType != 'areaList') : []
            _self.dictsList = [...arr, ..._self.dictsList]
            await Promise.all(_self.dictsItem(_self.dictsList))
            return new Promise((resolve, reject) =>{
                resolve(_self.dictsList)
            })
        },
        // 初始化具体字典
        dictsItem(list) {
            let _self = this, arr = []
            let fn = (item) => {
                return new Promise((resolve, reject) => {
                    if(item['deptType'] == 'activityType'){
                        getActiveTypeDict().then(res => {
                            let list = res.data.map(i => {
                                return {dictLabel: i.activityType, dictValue: i.id}
                            })
                            _self.$set(item, 'child', [...item.child || [], ...list])
                            resolve(item)
                        })
                    }else if(item['deptType'] == 'activateUser'){ // 激活人
                        getActivateUserList().then(res => {
                            let list = res.data.map(i => {
                                return {dictLabel: i.nickName, dictValue: i.nickName}
                            })
                            _self.$set(item, 'child', [...item.child || [], ...list])
                            resolve(item)
                        })
                    } else if(item['deptType'] == 'verificationUser'){ // 核销员
                        getVerificationUserList().then(res => {
                            let list = res.data.map(i => {
                                return {dictLabel: i, dictValue: i}
                            })
                            _self.$set(item, 'child', [...item.child || [], ...list])
                            resolve(item)
                        })
                    } else if(item['deptType'] == 'shopList'){ // 活动商家 、 核销商家
                        getShopListDict().then(res => {
                            let list = res.data.map(i => {
                                return {dictLabel: i.shopName, dictValue: i.id}
                            })
                            _self.$set(item, 'child', [...item.child || [], ...list])
                            resolve(item)
                        })
                    }else{
                        getDictList(item['deptType']).then(res => {
                            _self.$set(item, 'child', [...item.child || [], ...res.data])
                            resolve(item)
                        });
                    }
                    
                })
            }
            list.filter(item => item.deptType).forEach(item =>{
                if (item.isAera) return
                arr.push(fn(item))
            })
            return arr
        }
    },
}
